import sqlite3
import random


def simulateUser():
    conn = sqlite3.connect('./data/videoset.db')
    conn.isolation_level = None  # 自动提交修改，不用手动commit
    cur = conn.cursor()
    cur.execute('CREATE TABLE IF NOT EXISTS UserFeedback (recordID INTEGER PRIMARY KEY, uid INTEGER, videoID INTEGER, '
                'timeRatio REAL, '
                'danmaku INTEGER, reply INTEGER, like INTEGER, coin INTEGER, favorite INTEGER, share INTEGER)')
    record = 0
    for uid in range(100):
        vid = []
        for pos in range(15):
            for i in range(5):
                rand = random.randint(pos*30, pos*30+29)
                while rand in vid:
                    rand = random.randint(pos*30, pos*30+29)
                vid.append(rand)
        for videoid in vid:
            timeratio = random.random()
            danmaku = random.randint(0, 1)
            reply = random.randint(0, 1)
            like = random.randint(0, 1)
            coin = random.randint(0, 2)
            favorite = random.randint(0, 1)
            share = random.randint(0, 1)
            inp = '(' + str(record) + ',' + str(uid) + ',' + str(videoid) + ',' + str(timeratio) + ',' + str(danmaku) \
                  + ',' + str(reply) + ',' \
                  + str(like) + ',' + str(coin) + ',' + str(favorite) + ',' + str(share) + ')'
            cur.execute('INSERT INTO UserFeedback VALUES' + inp)
            record += 1
        print('User record ' + str(uid) + ' prepared.')
    cur.close()
    conn.close()


if __name__ == '__main__':
    simulateUser()

